package com.chixing.ih.module.programmer.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.programmer.pojo.Attention;
import com.chixing.ih.module.programmer.pojo.dto.AttentionDTO;
import com.chixing.ih.module.programmer.service.IAttentionService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/4
 * Time: 11:08
 */
@RestController
@RequestMapping("/attention")
@Api(tags = "程序员模块关注相关Api")
public class AttentionController {
    @Autowired
    IAttentionService attentionService;

    /**
     * desc:查看关注接口
     *
     * @param followerId
     * @return
     */
    @ApiOperation(value = "查看关注接口", notes = "查看用户关注的所有程序员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "followerId", value = "关注人的id", required = true, dataType = "long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("/listFollower/{followerId}")
    public Map<String, Object> listFollowers(@PathVariable("followerId") long followerId) {
        List<AttentionDTO> attentionDTOS = attentionService.listFollower(followerId);
        return ResponseData.REP_GET_SUCCESS(attentionDTOS);

    }

    /**
     * desc:查看粉丝接口
     *
     * @param followedId
     * @return
     */
    @ApiOperation(value = "查看粉丝接口", notes = "查看用户所有粉丝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "followedId", value = "被关注人的id", required = true, dataType = "long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("/listFan/{followedId}")
    public Map<String, Object> listFans(@PathVariable("followedId") long followedId) {
        List<AttentionDTO> attentionDTOS = attentionService.listFan(followedId);
        return ResponseData.REP_GET_SUCCESS(attentionDTOS);


    }

    /**
     * desc:关注接口
     *
     * @param attention
     * @return
     */
    @ApiOperation(value = "关注接口", notes = "点击关注程序员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "followerId", value = "关注者id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "followedId", value = "被关注者的id", required = true, dataType = "long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "关注成功"),
            @ApiResponse(code = 400, message = "关注失败")
    })
    @PostMapping("/attention")
    public Map<String, Object> saveAttention(@RequestBody Attention attention) {
        boolean flag = attentionService.saveAttention(attention);
        if (flag)
            return ResponseData.REP_CREATED_SUCCESS();
        else
            return ResponseData.REP_INVALID_ERROR();

    }

    /**
     * desc:取消关注接口
     *
     * @param followerId
     * @param followedId
     * @return
     */
    @ApiOperation(value = "取消关注接口", notes = "点击取消关注程序员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "followerId", value = "关注者id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "followedId", value = "被关注者的id", required = true, dataType = "long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "取消关注成功"),
            @ApiResponse(code = 400, message = "取消关注失败")
    })
    @DeleteMapping("/attention/{followerId}/{followedId}")
    public Map<String, Object> deleteAttention(@PathVariable("followerId") long followerId, @PathVariable("followedId") long followedId) {
        boolean flag = attentionService.deleteAttention(followerId, followedId);
        if (flag)
            return ResponseData.REP_CREATED_SUCCESS();
        else
            return ResponseData.REP_INVALID_ERROR();

    }


}
